package com.hwl.demo16.entity;

/**
 * @author sentry
 * @since 2023-03-25
 */
public class Singleton {

    private volatile static Singleton instance;
    // 静态初始化
    // private static Singleton instance = new Singleton();

    private Singleton() {

    }

    /**
     * 双重否定
     */
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}
